package com.cet.lxf.collection.test02;

import java.util.List;
import java.util.Objects;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-04 10:21
 **/
public class Main01 {
    public static void main(String[] args) {
        List<Person01> list = List.of(
                new Person01("Xiao", "Ming", 18),
                new Person01("Xiao", "Hong", 25),
                new Person01("Bob", "Smith", 20)
        );
        boolean exist = list.contains(new Person01("Bob", "Smith", 20));
        System.out.println(exist ? "测试成功!" : "测试失败!");
    }
}

class Person01 {
    String firstName;
    String lastName;
    int age;
    public Person01(String firstName, String lastName, int age) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Person01)) {
            return false;
        }
        Person01 p = (Person01) o;
        return Objects.equals(firstName,p.firstName)
                && Objects.equals(lastName,p.lastName)
                && age == p.age;
    }
}
